/**
 * 
 */
package com.desitek.cricket.dao.hibernate;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.desitek.cricket.repository.GenericRepository;

/**
 * @author Dhiraj
 * 
 */
public class GenericDAO<T> extends BaseHibernateDAO
		implements GenericRepository<T> {
	private static final Logger log = Logger.getLogger(GenericDAO.class);
	/**
	 * 
	 */

	@SuppressWarnings("unused")
	private Class<T> persistenceClass;

	public void delete(T object) {
		log.info("deleting group");
		Transaction tx = null;
		Session session = getSession();
		tx = session.beginTransaction();
		try {

			session.delete(object);
			tx.commit();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			tx.rollback();
			log.error(e);
		}

	}

	public void save(T object) {
		log.info("adding group");
		Transaction tx = null;
		Session session = getSession();
		tx = session.beginTransaction();
		try {

			session.save(object);
			tx.commit();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			tx.rollback();
			log.error(e);
		}
	}

	public void update(T object) {
		log.info("updating group");
		Transaction tx = null;
		Session session = getSession();
		tx = session.beginTransaction();
		try {

			session.update(object);
			tx.commit();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			tx.rollback();
			log.error(e);
		}
	}

}
